package com.siwei.mes.entity.experiment.slag;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.Map;

/**
 * @Description: 矿渣粉-流动度比
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class SlagLddb {
    @ApiModelProperty(value = "试验结果")//1
    private String syjg = "";
    @ApiModelProperty(value = "单项结论")//1
    private String dxjl = "";
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "试验胶砂流动度信息")
    private SlagLddb.Syjsldd syjsldd = new SlagLddb.Syjsldd();
    @ApiModelProperty(value = "对比胶砂流动度信息")
    private SlagLddb.Dbjsldd dbjsldd = new SlagLddb.Dbjsldd();

    @Data
    @Accessors(chain = true)
    @ApiModel("对比胶砂流动度信息")
    public static class Dbjsldd {
        @ApiModelProperty(value = "试验水泥量")
        private String sysnl = "";
        @ApiModelProperty(value = "细骨料用量")
        private String xglyl = "";
        @ApiModelProperty(value = "水用量")
        private String syl = "";
        @ApiModelProperty(value = "直径1")
        private String zj1 = "";
        @ApiModelProperty(value = "直径2")
        private String zj2 = "";
        @ApiModelProperty(value = "流动度")
        private String ldd = "";
    }

    @Data
    @Accessors(chain = true)
    @ApiModel("试验胶砂流动度信息")
    public static class Syjsldd {
        @ApiModelProperty(value = "试验水泥量")
        private String sysnl = "";
        @ApiModelProperty(value = "试验矿渣粉用量")
        private String sykzfyl = "";
        @ApiModelProperty(value = "水用量")
        private String syl = "";
        @ApiModelProperty(value = "直径1")
        private String zj1 = "";
        @ApiModelProperty(value = "直径2")
        private String zj2 = "";
        @ApiModelProperty(value = "矿渣粉用量")
        private String kzfyl = "";
        @ApiModelProperty(value = "流动度")
        private String ldd = "";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        SlagLddb entity = new SlagLddb();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, SlagLddb.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, SlagLddb.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        SlagLddb entity = JsonUtils.getObject(objJson, SlagLddb.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getSyjg()) || "null".equals(entity.getSyjg())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        /*if (StringUtils.isBlank(entity.getDxjl()) || "null".equals(entity.getDxjl())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }*/
        return null;
    }

    public static void setValue(SlagLddb entity, Map<String, Object> data) {
        SlagLddb.Syjsldd syjsldd = entity.getSyjsldd();
        SlagLddb.Dbjsldd dbjsldd = entity.getDbjsldd();
        if(data.get("DbYPLDD") != null){
            dbjsldd.setLdd(data.get("DbYPLDD").toString());
        }
        if(data.get("SyYPLDD") != null){
            syjsldd.setLdd(data.get("SyYPLDD").toString());
        }
        if(data.get("Conclusion") != null){
            entity.setDxjl(data.get("Conclusion").toString());
        }
        if(data.get("LDDB") != null){
            entity.setSyjg(data.get("LDDB").toString());
        }
    }
}
